//
//  Cloud_ViewController.m
//  EggSteward
//
//  Created by 王道林 on 16/9/1.
//  Copyright © 2016年 王道林. All rights reserved.
//
#import "DLMacro.h"
#import "Cloud_ViewController.h"
#import "BaseTableView.h"
#import "BaseButton.h"
#import "BaseView.h"
#import "Cloud_tableViewCellOne.h"
#import "Cloud_tableViewCellTwo.h"
#import "Cloud_tableViewCellThree.h"
#import "Cloud_tableViewCellFour.h"
#import "Cloud_tableViewCellFive.h"
#import "Cloud_tableViewCellSix.h"
@interface Cloud_ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) BaseTableView *tableView;
@end

@implementation Cloud_ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"云检测";
    [self createSubview];
}

- (void)createSubview
{
    _tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, self.view.frame.size.height - 64 - 49) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self createTableViewFootView];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [[NSNotificationCenter defaultCenter] removeObserver:_tableView name:@"night" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:_tableView name:@"day" object:nil];
    [self.view addSubview:_tableView];
    // 注册cell
    [_tableView registerClass:[Cloud_tableViewCellOne class] forCellReuseIdentifier:@"reuseOne"];
    [_tableView registerClass:[Cloud_tableViewCellTwo class] forCellReuseIdentifier:@"reuseTwo"];
    [_tableView registerClass:[Cloud_tableViewCellThree class] forCellReuseIdentifier:@"reuseThree"];
    [_tableView registerClass:[Cloud_tableViewCellFour class] forCellReuseIdentifier:@"reuseFour"];
    [_tableView registerClass:[Cloud_tableViewCellFive class] forCellReuseIdentifier:@"reuseFive"];
    [_tableView registerClass:[Cloud_tableViewCellSix class] forCellReuseIdentifier:@"reuseSix"];


    
}
#pragma mark - tableView的协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 8;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 6) {
        return 3;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section < 3) {
        Cloud_tableViewCellOne *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseOne" forIndexPath:indexPath];
        return cell;
    } else if (indexPath.section == 3)
    {
       Cloud_tableViewCellTwo *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseTwo" forIndexPath:indexPath];
        return cell;
    } else if (indexPath.section == 4)
    {
        Cloud_tableViewCellThree *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseThree" forIndexPath:indexPath];
        return cell;
    } else if (indexPath.section == 5)
    {
        Cloud_tableViewCellFour *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseFour" forIndexPath:indexPath];
        return cell;
    } else if (indexPath.section == 6)
    {
        Cloud_tableViewCellFive *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseFive" forIndexPath:indexPath];
        cell.blockBegenText = ^()
        {
            [UIView beginAnimations:@"wang" context:nil];
            [UIView setAnimationDuration:0.3];
            _tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 216);
            [UIView commitAnimations];
        };
        cell.blockEndText = ^()
        {
            [UIView beginAnimations:@"wang" context:nil];
            [UIView setAnimationDuration:0.3];
            _tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
            [UIView commitAnimations];
            
        };
        if (indexPath.row == 0) {
            cell.textView.text = @"临床表现:";
            return cell;
        }
        else if (indexPath.row == 1)
        {
            cell.textView.text = @"剖检症状:";
            return cell;
        }
        else
        {
            cell.textView.text = @"用药及免疫程序:";
            return cell;
        }
        
    }
    else
    {
        Cloud_tableViewCellSix *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseSix" forIndexPath:indexPath];
        cell.blockBegenText = ^()
        {
            [UIView beginAnimations:@"wang" context:nil];
            [UIView setAnimationDuration:0.3];
            _tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 216);
            [UIView commitAnimations];
        };
        cell.blockEndText = ^()
        {
            [UIView beginAnimations:@"wang" context:nil];
            [UIView setAnimationDuration:0.3];
            _tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
            [UIView commitAnimations];
            
        };

        return cell;
    }
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSArray *arr = [NSArray arrayWithObjects:@"送检人信息:", @"养殖场主信息:", @"技术厂长信息:",@"养殖场信息:", @"检测信息:", @"检测目的:", @"鸡群及防御情况:", @"检测项目:",nil];
    return arr[section];
}
// cell 的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section < 3) {
        return 120;
    } else if (indexPath.section == 3)
    {
        return 160;
    } else if (indexPath.section == 4)
    {
        return 140;
    } else if (indexPath.section == 5)
    {
        return 100;
    } else if (indexPath.section == 6)
    {
        return 150;
    } else
    {
        return 50;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20;
}

#pragma mark - 创建tableView的尾视图
- (void)createTableViewFootView
{
    BaseView *view = [[BaseView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
    view.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    _tableView.tableFooterView = view;
    BaseButton *button = [BaseButton buttonWithType:UIButtonTypeSystem];
    [view addSubview:button];
    button.frame = CGRectMake(30, 0, self.view.frame.size.width - 60, 50);
    [button setBackgroundColor:[UIColor colorWithRed:0.157 green:0.651 blue:0.278 alpha:1.000]];
    button.layer.masksToBounds = YES;
    button.layer.cornerRadius = 25;
    [button setTitle:@"提交" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
